package net.jescort.persistence.dao.eclipselink;

import net.gelif.kernel.persistence.dao.eclipselink.GenericEclipseLinkDao;
import net.jescort.domain.user.User;
import net.jescort.persistence.dao.UserDao;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;


@Repository("userDao")
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class UserJpaDao extends GenericEclipseLinkDao<User, Integer> implements UserDao
{
    @Override
    public User findByUsername(String username)
    {
        return (User)entityManager.createQuery("SELECT user FROM User user WHERE user.username = :username").setParameter("username", username).getSingleResult();
    }

    public String findPasswordByUsername(String username)
    {
        return (String)entityManager.createQuery("SELECT user.password FROM User user WHERE user.username = :username").setParameter("username", username).getSingleResult();
    }
}
